import sys, os
sys.path.append(os.path.abspath('..')) # For accesing the module

from lsar import Lsar, JsonResultItemZip, JsonResultItemTar, JsonResultItemRar

lsar = Lsar()
lsar.file = 'example.zip'

result = None
try:
	# This is needed to fetch usefull data fron lsar.
	result = lsar.fetch()
except UnknownOption as err:
	print("Version mismatch? Error: {0}".format(err))
except ArchiveNotFound as err:
	print("ArchiveNotFound Error: {0}".format(err))
except UnknownOption as err:
	print("PasswordRequired Error: {0}".format(err))
except UnknownOption as err:
	print("ParseError Error: {0}".format(err))
except UnknownOption as err:
	print("UnarchiveError Error: {0}".format(err))
except UnknownFormatError as err:
	print("UnarchiveError Error: {0}".format(err))

if result:
	print("Format: {0}".format(result.formatName()))
	print("formatVersion: {0}".format(result.formatVersion()))
	print("contents: {0}".format(result.contents()))
	print("encoding: {0}".format(result.encoding()))
	print("confidence: {0}".format(result.confidence()))
	print("properties: {0}".format(result.properties()))
	print("isEncrypted: {0}".format(result.isEncrypted()))
	print("archiveName: {0}".format(result.archiveName()))
	print("volumes: {0}".format(result.volumes()))
	print("isMultiArchive: {0}".format(result.isMultiArchive()))

	print("\n----\nContent:")

	for fileObject in result.contentsObjects():
		print("\tType: {0}".format(type(fileObject)))
		print("\tName: {0}".format(fileObject.name()))
		print("\tIndex: {0}".format(fileObject.index()))

		if type(fileObject) == JsonResultItemZip:
			print("\t\tlocalDate: {0}".format(fileObject.localDate()))
			print("\t\tcompressionMethod: {0}".format(fileObject.compressionMethod()))
			print("\t\textractVersion: {0}".format(fileObject.extractVersion()))
			print("\t\tOS: {0}".format(fileObject.OS()))
			print("\t\tCRC32: {0}".format(fileObject.CRC32()))
			print("\t\tfileAttributes: {0}".format(fileObject.fileAttributes()))
			print("\t\tflags: {0}".format(fileObject.flags()))
			print("\t\tOSName: {0}".format(fileObject.OSName()))

		elif type(fileObject) == JsonResultItemTar:
			print("\t\tisSparseFile: {0}".format(fileObject.isSparseFile()))

		elif type(fileObject) == JsonResultItemRar:
			print("\t\tattributes: {0}".format(fileObject.attributes()))
			print("\t\tsolidIndex: {0}".format(fileObject.solidIndex()))
			print("\t\tcompressionVersion: {0}".format(fileObject.compressionVersion()))
			print("\t\tcompressionMethod: {0}".format(fileObject.compressionMethod()))
			print("\t\tOS: {0}".format(fileObject.OS()))
			print("\t\tCRC32: {0}".format(fileObject.CRC32()))
			print("\t\tflags: {0}".format(fileObject.flags()))
			print("\t\tOSName: {0}".format(fileObject.OSName()))

		print()
